package com.tank.audio;

import java.util.HashMap;
import java.util.Map;

/**
 * TODO
 *
 * @author chenwb
 * @since 2024/1/28 13:44
 */
public class AudioFactory {
    //单例模式
    private static AudioFactory INSTANCE;

    private static final Map<String, Audio> AUDIO_MAP = new HashMap<>();
    private static final String EXPLODE = "explode";
    private static final String FIRE = "fire";
    private static final String WAR = "war";
    private static final String TANK_MOVE = "tank_move";

    private AudioFactory() {
        AUDIO_MAP.put(EXPLODE, new Audio("static/audio/explode.wav"));
        AUDIO_MAP.put(FIRE, new Audio("static/audio/tank_fire.wav"));
        AUDIO_MAP.put(WAR, new Audio("static/audio/war1.wav"));
        AUDIO_MAP.put(TANK_MOVE, new Audio("static/audio/tank_move.wav"));
    }

    // 懒汉式
    public static AudioFactory getInstance() {
        if (INSTANCE == null) {
            synchronized (AudioFactory.class) {
                if (INSTANCE == null) {
                    INSTANCE = new AudioFactory();
                }
            }
        }
        return INSTANCE;
    }

    public Audio getExplodeAudio() {
        return AUDIO_MAP.get(EXPLODE);
    }

    public Audio getFireAudio() {
        return AUDIO_MAP.get(FIRE);
    }

    public Audio getWarAudio() {
        return AUDIO_MAP.get(WAR);
    }

    public Audio getTankMoveAudio() {
        return AUDIO_MAP.get(TANK_MOVE);
    }
}
